﻿@{
    ViewBag.Title = "角色列表";
}

<script src="~/Script/laypage/laypage.js"></script>

<form method="post" action="/managerrole/list" id="form1">
    <!--导航栏-->
    <div class="location">
        <a href="javascript:history.back(-1);" class="back"><i></i><span>返回上一页</span></a>
        <a href="/Home/center" class="home"><i></i><span>首页</span></a>
        <i class="arrow"></i>
        <span>角色管理</span>
    </div>
    <!--/导航栏-->
    <!--工具栏-->
    <div id="floatHead" class="toolbar-wrap" style="height: 52px;">
        <div class="toolbar" style="width: 1156px;">
            <div class="box-wrap">
                <a class="menu-btn"></a>
                <div class="l-list">
                    <ul class="icon-list">
                        <li><a class="add" href="/managerrole/edit"><i></i><span>新增</span></a></li>
                        <li><a class="all" href="javascript:;" onclick="checkAll(this);"><i></i><span>全选</span></a></li>
                        <li><a onclick="return ExePostBack('DelRole', '本操作会删除角色及相关权限，是否继续？');" id="DelRole" class="del" href="/ManagerRole/Del"><i></i><span>删除</span></a></li>
                    </ul>
                </div>
                <div class="r-list">
                    <input name="M_Name" type="text" id="M_Name" class="keyword" value="@(ViewBag.P_Name as string)">
                    <a id="lbtnSearch" class="btn-search" href="javascript:void(0);" onclick="return Search(this)">查询</a>
                </div>
            </div>
        </div>
    </div>
    <!--/工具栏-->
    <!--列表-->
    <div class="table-container">
        <table style="width:100%"  border="0" cellspacing="0" cellpadding="0" class="ltable">
            <tbody id="tbody1"></tbody>
        </table>

    </div>
    <div class="common_page clearfix">
        <div class="fy_right fr page" id="page1">

        </div>
    </div>
    <!--/分页列表-->
    <script type="text/javascript">
        $(function () {
            bindFocusMyproject();
        });
        function bindFocusMyproject(curr) {
            var str = "<tr class='odd_bg'>"
                        + "<th width='8%'>选择</th>"
                        + "<th align='left'>角色名称</th>"
                        + "<th width='12%' align='left'>类型</th>"
                        + "<th width='12%'>操作</th>"
                    + "</tr>";
            $("#tbody1").empty();
            var data = { Name: $("#M_Name").val(), pageIndex: curr || 1, pageSize: 10 };
            $.getJSON('@Url.Action("ManagerRoleList", "ManagerRole")', data, function (res) {

                //此处仅仅是为了演示变化的内容
                if (res.Items.length > 0) {

                    for (var i = 0; i < res.Items.length; i++) {
                        str += "<tr " + (i % 2 == 0 ? 'class=\'odd_bg\'' : '') + ">"
                        + "<td align='center'>"
                        + "<span class='checkall' style='vertical-align:middle;'>"
                        + "<input id='rptList' type='checkbox' name='rptList' value='" + res.Items[i].Id + "'>"
                        + "</span>"
                        + "</td>"
                        + "<td><a href='/ManagerRole/Edit?id=" + res.Items[i].Id + "'>" + res.Items[i].role_name + "</a></td>"
                        + "<td>" + (res.Items[i].RoleType == 0 ? '系统用户' : '非系统用户') + "</td>"
                        + "<td align='center'><a href='/ManagerRole/Edit?id=" + res.Items[i].Id + "'>修改</a></td>"
                        + "</tr>";
                    }
                    $("#tbody1").append(str);
                    $("#page1").show();
                    //显示分页
                    laypage({
                        cont: 'page1', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
                        pages: res.Count, //通过后台拿到的总页数
                        curr: curr || 1, //当前页
                        skip: true,
                        jump: function (obj, first) { //触发分页后的回调
                            if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                                bindFocusMyproject(obj.curr);
                            }
                        }
                    });
                } else {
                    $("#tbody1").append("<tr><td colspan='8'>未查询到数据</td></tr>");
                    $("#page1").hide();
                }
            });
        }

    </script>
</form>
